﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Honestysoft.Baseframework.WebUI;
using Honestysoft.Financing.Model;
using Honestysoft.BaseObject;
using System.Data.Common;

namespace Honestysoft.Financing.WebUI.Module.Audit
{
    public partial class AuditTableReceive : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            txtTransactName.Enabled = false;
            txtTranTime.Enabled = false;
            Bu_BatchRec rec = new Honestysoft.BaseObject.BaseBusinessLogic<Bu_BatchRec>(Globals.CurrentConnStringName).GetEntity(Request.QueryString["ID"]);
            if (rec.IsReceive)//已签收
            {
                txtTransactName.Text = rec.ToUserName;
                txtTranTime.Text = rec.RecTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                txtOpinion.Text = rec.RecOpinion;
                txtOpinion.Enabled = false;
                btnOK.Enabled = false;
            }
            else
            {
                txtTransactName.Text = UserLoginer.LoginUser.Name;
                txtTranTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                bool bRet = new Honestysoft.Financing.BusinessLogic.Audit(Globals.CurrentConnStringName).ReceiveBatchRec(Request.QueryString["ID"], Convert.ToDateTime(txtTranTime.Text), txtOpinion.Text);
                if (bRet)
                {
                    ScriptHelper.Window.AlertClose("签收成功！", true);
                }
                else
                {
                    ScriptHelper.Window.Alert("签收失败！");
                }
            }
            catch (Exception ex)
            {
                Honestysoft.BaseLibrary.ExceptionHandling.ExceptionHelper.ExceptionDistribute(ex, false);
                ScriptHelper.Window.Alert("签收失败！\r\n" + ex.Message);
            }
        }
    }
}